package handler

import (
	"github.com/gin-gonic/gin"
	"live-broadcast/api/request"
	"live-broadcast/internal/dao"
	"live-broadcast/internal/model"
	"net/http"
)

func AddBarrage(c *gin.Context) {
	var req request.AddBarrageForm
	var barrage model.Barrage

	if err := c.ShouldBind(&req); err != nil {
		return
	}

	if req.UserId == 0 || req.Info == "" {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "验证失败",
			"data": nil,
		})
		return
	}

	barrage = model.Barrage{
		UserId: req.UserId,
		Info:   req.Info,
	}

	err := dao.AddFile(&barrage)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "发送失败",
			"data": false,
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "发送成功",
		"data": barrage.Info,
	})

}
